/**
 * <p>
 * Created on 2006-6-13 14:28:16 <br>
 * Copyright (c) 2006, All rights reserved.
 * </p>
 * @author Widen
 */
package com.widen.prima.editor.finance;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

public class BookOfAccountInputEditor
    extends EditorPart
{
    public static final String ID = "com.widen.prima.editor.input_book_of_account";

    private BookOfAccountInputPanel panel;
    private IPartListener partListener = new IPartListener()
    {
        public void partOpened(IWorkbenchPart part)
        {
        }

        public void partClosed(IWorkbenchPart part)
        {
        }

        private void trackActivatedEditors(IWorkbenchPart part)
        {
            if (!(part instanceof BookOfAccountInputEditor))
            {
                return;
            }
            panel.loadSubjects();
        }

        public void partActivated(IWorkbenchPart part)
        {
            trackActivatedEditors(part);
        }

        public void partBroughtToTop(IWorkbenchPart part)
        {
        }

        public void partDeactivated(IWorkbenchPart part)
        {
        }
    };

    public BookOfAccountInputEditor()
    {
        super();
    }

    public void doSave(IProgressMonitor monitor)
    {
    }

    public void doSaveAs()
    {
    }

    public void init(IEditorSite site, IEditorInput input)
        throws PartInitException
    {
        setSite(site);
        setInput(input);
        setPartName(((BookOfAccountInputInput) input).getName());
    }

    public boolean isDirty()
    {
        return false;
    }

    public boolean isSaveAsAllowed()
    {
        return false;
    }

    public void createPartControl(Composite parent)
    {
        getSite().getWorkbenchWindow().getPartService().addPartListener(
            partListener);
        panel = new BookOfAccountInputPanel(parent, SWT.NONE);
    }

    public void setFocus()
    {
    }

    public void dispose()
    {
        getSite().getWorkbenchWindow().getPartService().removePartListener(
            partListener);
        super.dispose();
    }
}
